<!--
 * @Author: xu xuejia
 * @Date: 2021-12-07 14:27:53
 * @LastEditors: xu xuejia
 * @LastEditTime: 2021-12-20 19:28:18
 * @LastEditors: Hongting Yuan
 * @LastEditTime: 2021-12-12 12:43:30
 * @Description: 初审页面
 * @FilePath: \Management-of-Scientific-Research-in-Universities-Front\src\views\projectexam\Firstexam.vue
-->
<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ name:'WorkPlace' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>项目审核</el-breadcrumb-item>
      <el-breadcrumb-item>项目初审</el-breadcrumb-item>
      <!-- <router-link :to="{name:'WorkPlace'}">工作台</router-link> -->
    </el-breadcrumb>
    <!--待办任务卡片区-->
    <div style="display:flex">
      <div style="width:49%">
        <el-card shadow="always">
          <div class="Titletext">我的待办</div>
          <div class="cardtext">{{ notpass }}个任务</div>
        </el-card>
      </div>
      <div style="width:49%;margin-left:2%">
        <el-card shadow="always">
          <div class="Titletext">本周完成任务数</div>
          <div class="cardtext">{{ firstpass }}个任务</div>
        </el-card>
      </div>
    </div>
    <!--列表卡片区-->
    <el-card
      style="margin-top: 24px"
    >
      <el-row>
        <el-col>
          初审列表
        </el-col>
        <el-col :span="24">
          <my-tsble
            :data="tableData"
            :list-query="listQuery"
            @currentChange="currentChange"
            @sizeChange="sizeChange"
            @search="search"
            @radioChange="radioChange"
            @detail="detail"
          />
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
import axios from 'axios'
import crypto from '../../crypto/crypto'
import MyTsble from '../../components/MyTsble'
export default {
  name: 'Rewardexam',
  components: { MyTsble },
  data() {
    return {
      tableData: { // 此为从后台获取得表格数据
        list: [],
        nextPage: 0,
        pageNum: 1,
        pageSize: 10,
        pages: 0,
        prePage: 0,
        size: 0,
        total: 10
      },
      listQuery: {
        page: 1,
        pageSize: 10,
        total: 0,
        query: ''
      },
      // filterStatus: '全部',
      flag: '1',
      projectName: '',
      peId: '',
      introduction: '',
      team: '',
      logo: '',
      list: [],
      userlist: [],
      departmentlist: [],
      levellist: [],
      atlist: [],
      ctlist: [],
      naturelist: [],
      sclist: [],
      subjectlist: [],
      firstpass: 0,
      notpass: 0,
      listarr: [],
      total1: 0,
      total2: 0,
      filterStatus1: '全部'
    }
  },
  created() {
    // this.getUserList()
    this.getTask()
  },
  mounted() {
    this.getProjectList()
    this.getDepartmentList()
    // this.getList()
  },
  methods: {
    /**
     * @description:任务卡片数据
     * @param {*}
     * @return {*}
     * @author: xu xuejia
     */
    // 任务卡片数据
    getTask() {
      axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 1 })
        .then((response) => {
          if (response.data.data) {
            this.notpass = response.data.data.total
          }
        }).catch(error => {
          console.log(error)
        })
      axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 2 })
        .then((response) => {
          if (response.data.data) {
            this.firstpass = response.data.data.total
          }
        }).catch(error => {
          console.log(error)
        })
    },
    /**
     * @description: 筛选数据
     * @param {*}
     * @return {*}
     * @author: xu xuejia
     */
    // 筛选数据
    async radioChange(val) {
      this.filterStatus1 = val
      if (val === '全部') {
        axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize })
          .then((response) => {
            this.tableData.list = response.data.data.list
            this.listQuery.total = response.data.data.total
            for (let index = 0; index < this.tableData.list.length; index++) {
              this.userlist = response.data.data.list[index].team
              this.tableData.list[index].planTime = this.getdata(this.tableData.list[index].planTime)// 转时间
              this.tableData.list[index].leaderId = this.getName(this.tableData.list[index].leaderId)// 转负责人id
              this.tableData.list[index].departmentId = this.getdepartmentName(this.tableData.list[index].departmentId)// 转所属单位id
            }
          }).catch(error => {
            console.log(error)
          })
      }
      if (val === '未通过') {
        axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 1 })
          .then((response) => {
            if (response.data.data == null) {
              this.tableData.list = null
              this.listQuery.total = 0
            } else {
              this.tableData.list = response.data.data.list
              this.listQuery.total = response.data.data.total
              this.notpass = response.data.data.total
              for (let index = 0; index < this.tableData.list.length; index++) {
                this.userlist = response.data.data.list[index].team
                this.tableData.list[index].planTime = this.getdata(this.tableData.list[index].planTime)// 转时间
                this.tableData.list[index].leaderId = this.getName(this.tableData.list[index].leaderId)// 转负责人id
                this.tableData.list[index].departmentId = this.getdepartmentName(this.tableData.list[index].departmentId)// 转所属单位id
              }
            }
          }).catch(error => {
            console.log(error)
          })
      }
      if (val === '初审通过') {
        axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 2 })
          .then((response) => {
            if (response.data.data == null) {
              this.tableData.list = null
              this.listQuery.total = 0
            } else {
              this.tableData.list = response.data.data.list
              this.listQuery.total = response.data.data.total
              this.firstpass = response.data.data.total
              for (let index = 0; index < this.tableData.list.length; index++) {
                this.userlist = response.data.data.list[index].team
                this.tableData.list[index].planTime = this.getdata(this.tableData.list[index].planTime)// 转时间
                this.tableData.list[index].leaderId = this.getName(this.tableData.list[index].leaderId)// 转负责人id
                this.tableData.list[index].departmentId = this.getdepartmentName(this.tableData.list[index].departmentId)// 转所属单位id
              }
            }
          }).catch(error => {
            console.log(error)
          })
      }
      // if (val === '复审通过') {
      //   await axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 3 })
      //     .then((response) => {
      //       this.listarr.push(response.data.data.list)
      //       this.total1 = response.data.data.total
      //     }).catch(error => {
      //       console.log(error)
      //     })
      //   await axios.post('/pe/getAllByStAndDe/1', { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 4 })
      //     .then((response) => {
      //       this.listarr.push(response.data.data.list)
      //       this.total2 = response.data.data.total
      //     }).catch(error => {
      //       console.log(error)
      //     })
      //   console.log(this.listarr)
      //   this.tableData.list = this.listarr
      //   this.listQuery.total = this.total1 + this.total2
      // }
    },
    /**
     * @description: 页面以及页面条数改变
     * @param {*}
     * @return {*}
     * @author: xu xuejia
     */
    // 当前页面改变时
    currentChange(val) {
      this.listQuery.page = val
      if (this.filterStatus1 === '全部') {
        this.radioChange('全部')
      } else if (this.filterStatus1 === '未通过') {
        this.radioChange('未通过')
      } else if (this.filterStatus1 === '初审通过') {
        this.radioChange('初审通过')
      }
    },
    // 每页条数发生改变时
    sizeChange(val) {
      // this.listQuery.page = 1
      this.listQuery.pageSize = val
      if (this.filterStatus1 === '全部') {
        this.radioChange('全部')
      } else if (this.filterStatus1 === '未通过') {
        this.radioChange('未通过')
      } else if (this.filterStatus1 === '初审通过') {
        this.radioChange('初审通过')
      }
    },
    /**
     * @description: 获取项目
     * @param {*}
     * @return {*}
     * @author: xu xuejia
     */
    async getProjectList() {
      await axios.get(`/pe/getAll/${this.flag}`, { params: { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize }})
        .then((response) => {
          // this.tableData.list = response.data.data.list
          // this.listQuery.total = response.data.data.total
          // for (let index = 0; index < this.tableData.list.length; index++) {
          //   this.userlist = response.data.data.list[index].team
          //   this.tableData.list[index].planTime = this.getdata(this.tableData.list[index].planTime)// 转时间
          //   this.tableData.list[index].leaderId = this.getName(this.tableData.list[index].leaderId)// 转负责人id
          //   this.tableData.list[index].departmentId = this.getdepartmentName(this.tableData.list[index].departmentId)// 转所属单位id

          if (response.data.data) {
            this.tableData.list = response.data.data.list
            this.listQuery.total = response.data.data.total
            for (let index = 0; index < this.tableData.list.length; index++) {
              this.userlist = response.data.data.list[index].team
              this.tableData.list[index].planTime = this.getdata(this.tableData.list[index].planTime)// 转时间
              this.tableData.list[index].leaderId = this.getName(this.tableData.list[index].leaderId)// 转负责人id
              this.tableData.list[index].departmentId = this.getdepartmentName(this.tableData.list[index].departmentId)// 转所属单位id
              // this.tableData.list[index].aodId = this.getdepartmentName(this.tableData.list[index].aodId)// 转成果所属单位id
              // this.tableData.list[index].levelId = this.getlevelName(this.tableData.list[index].levelId)// 转成果所属单位id
              // this.tableData.list[index].atId = this.getatName(this.tableData.list[index].atId)// 转成果类型id
              // this.tableData.list[index].ctId = this.getctName(this.tableData.list[index].ctId)// 转ctid
              // this.tableData.list[index].natureId = this.getnatureName(this.tableData.list[index].natureId)// 转natureid
              // this.tableData.list[index].scId = this.getscName(this.tableData.list[index].scId)// 转scid
              // this.tableData.list[index].subjectId = this.getsubjectName(this.tableData.list[index].subjectId)// 转学科id
            }
          }
        }).catch(error => {
          console.log(error)
        })
      // for (var i = 0; i < this.tableData.list.length; i++) {
      //   if (this.tableData.list[i].examineStatus === '初审通过') {
      //     this.firstpass++
      //   } else if (this.tableData.list[i].examineStatus === '未通过') {
      //     this.notpass++
      //   }
      // }
    },
    /**
     * @description: 获取数据字典的数据
     * @param {*}
     * @return {*}
     * @author: xu xuejia
     */
    getList() {
      axios.get('dictionary/searchAll/level').then((response) => {
        this.levellist = response.data.data
      }).catch(error => {
        console.log(error)
      })
      // axios.get('dictionary/searchAll/achievementType').then((response) => {
      //   this.atlist = response.data.data
      // }).catch(error => {
      //   console.log(error)
      // })
      axios.get('dictionary/searchAll/conclusionType').then((response) => {
        this.ctlist = response.data.data
      }).catch(error => {
        console.log(error)
      })
      axios.get('dictionary/searchAll/nature').then((response) => {
        this.naturelist = response.data.data
      }).catch(error => {
        console.log(error)
      })
      axios.get('dictionary/searchAll/subjectCategory').then((response) => {
        this.sclist = response.data.data
      }).catch(error => {
        console.log(error)
      })
      axios.get('dictionary/searchAll/subject').then((response) => {
        this.subjectlist = response.data.data
      }).catch(error => {
        console.log(error)
      })
    },
    getUserList() {
      // axios.get('/user/getUsers').then((response) => {
      //   this.userlist = response.data.data
      // }).catch(error => {
      //   console.log(error)
      // })
      this.userlist = JSON.parse(this.$store.getters.getuser)
    },
    getDepartmentList() {
      // axios.get('dictionary/searchAll/department').then((response) => {
      //   this.departmentlist = response.data.data
      // }).catch(error => {
      //   console.log(error)
      // })
      this.departmentlist = JSON.parse(this.$store.getters.getdepartment)
    },
    search() {
      axios.get(`/pe/searchPEByName/${this.flag}`, { params: { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, projectName: this.listQuery.query }})
        .then((response) => {
          var dataarr = (JSON.stringify(response.data.data) === 'null') // 搜索的项目不存在时给message提示
          if (dataarr === true) {
            this.$message({
              showClose: true,
              type: 'warning',
              message: '项目不存在！'
            })
          }
          this.tableData.list = response.data.data.list
          this.listQuery.total = response.data.data.total
          for (let index = 0; index < this.tableData.list.length; index++) {
            this.userlist = response.data.data.list[index].team
            this.tableData.list[index].planTime = this.getdata(this.tableData.list[index].planTime)// 转时间
            this.tableData.list[index].leaderId = this.getName(this.tableData.list[index].leaderId)// 转负责人id
            this.tableData.list[index].departmentId = this.getdepartmentName(this.tableData.list[index].departmentId)// 转所属单位id
          }
        })
    },
    /**
     * @description: 任务卡片的数据
     * @param {*}
     * @return {*}
     * @author: xu xuejia
     */
    firstpassDisplay() {
      axios.post('/pe/getAllByStAndDe/1', { params: { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 2 }})
        .then((response) => {
          this.tableData.list = response.data.data.list
          this.listQuery.total = response.data.data.total
        }).catch(error => {
          console.log(error)
        })
    },
    notpassDisplay() {
      axios.post('/pe/getAllByStAndDe/1', { params: { pageNum: this.listQuery.page, pageSize: this.listQuery.pageSize, statusId: 1 }})
        .then((response) => {
          this.tableData.list = response.data.data.list
          this.listQuery.total = response.data.data.total
        }).catch(error => {
          console.log(error)
        })
    },
    /**
     * @description: 查看详情
     * @param {*} row
     * @return {*}
     * @author: xu xuejia
     */
    detail(row) {
      var pa = crypto.set('26')
      this.projectName = row.projectName
      this.peId = row.peId
      this.introduction = row.introduction
      this.team = row.team
      this.logo = row.fileMap.logo
      this.list = row
      sessionStorage.setItem('Team', JSON.stringify(this.team))
      sessionStorage.setItem('data', JSON.stringify(this.projectName))
      sessionStorage.setItem('key', JSON.stringify(this.peId))
      sessionStorage.setItem('Introduction', JSON.stringify(this.introduction))
      sessionStorage.setItem('Logo', JSON.stringify(this.logo))
      sessionStorage.setItem('List', JSON.stringify(this.list))
      this.$router.push({ path: '/' + pa, params: { data: this.projectName, key: this.peId, Team: this.team, Introduction: this.introduction, List: this.list }})
    },
    /**
     * @description: 转换各种id
     * @param {*} data
     * @return {*}
     * @author: xu xuejia
     */
    getatName(data) {
      // for (let i = 0; i < this.atlist.length; i++) {
      //   if (this.atlist[i].atId === data) {
      //     console.log(this.atlist[i].atName)
      //     return this.atlist[i].atName
      //   }
      // }
      var at = this.$store.getters.getat
      return at[data]
    },
    getctName(data) {
      // for (let i = 0; i < this.ctlist.length; i++) {
      //   if (this.ctlist[i].ctId === data) {
      //     return this.ctlist[i].ctName
      //   }
      // }
      var ct = this.$store.getters.getct
      return ct[data]
    },
    getnatureName(data) {
      // for (let i = 0; i < this.naturelist.length; i++) {
      //   if (this.naturelist[i].natureId === data) {
      //     return this.naturelist[i].natureName
      //   }
      // }
      var nature = this.$store.getters.getnature
      return nature[data]
    },
    getscName(data) {
      for (let i = 0; i < this.sclist.length; i++) {
        if (this.sclist[i].scId === data) {
          return this.sclist[i].scName
        }
      }
    },
    getsubjectName(data) {
      for (let i = 0; i < this.subjectlist.length; i++) {
        if (this.subjectlist[i].subjectId === data) {
          return this.subjectlist[i].subjectName
        }
      }
    },
    getlevelName(data) {
      for (let i = 0; i < this.levellist.length; i++) {
        if (this.levellist[i].levelId === data) {
          return this.levellist[i].levelName
        }
      }
    },
    // 转换负责人姓名id,从团队成员中获取
    getName(data) {
      for (let i = 0; i < this.userlist.length; i++) {
        if (this.userlist[i].userId === data) {
          return this.userlist[i].userRealname
        }
      }
      // if (this.userlist[data] === null) {
      //   return null
      // } else return this.userlist[data].realname
      // var username = this.$store.getters.getusername
      // return username[data]
    },
    // 转时间
    getdata(data) {
      var date = new Date(data)
      var Y = date.getFullYear() + '-'
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
      var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
      var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
      var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
      var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
      return Y + M + D + h + m + s
    },
    // 转所属单位id
    getdepartmentName(data) {
      // for (let i = 0; i < this.departmentlist.length; i++) {
      //   if (this.departmentlist[i].departmentId === data) {
      //     return this.departmentlist[i].departmentName
      //   }
      // }
      // this.departmentlist = JSON.parse(this.$store.getters.getdepartment)
      if (this.departmentlist[data] === null) {
        return null
      } else return this.departmentlist[data].name
    }
  }
}
</script>

<style lang="scss" scoped>
.cardtext{
  font-size: 24px;
  text-align: center;
}
.Titletext{
  font-size: 13px;
  color: #999;
  text-align: center;
}
</style>
